/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExportChooser.java
 *
 * Created on 24-mei-2009, 12:03:20
 */

package Gui;

import java.util.Vector;

import javax.swing.DefaultListModel;
import javax.swing.ListModel;

/**
 *
 * @author LESLEY
 */
public class ExportChooser extends javax.swing.JFrame {

    /** Creates new form ExportChooser */
    public ExportChooser(String items) {
        
        initComponents();
        setTitle("USIM Pro - Kies " + items.toLowerCase());
        usedItemsLabel.setText(items + " voor export: ");
        unusedItemsLabel.setText("Overige " + items.toLowerCase());

        pack();
        setLocationRelativeTo(null);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        usedListScrollPane = new javax.swing.JScrollPane();
        usedList = new javax.swing.JList();
        unusedListScrollPane = new javax.swing.JScrollPane();
        unusedList = new javax.swing.JList();
        usedItemsLabel = new javax.swing.JLabel();
        unusedItemsLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        Vector<Object> objectVector = new Vector<Object>();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("USIM Pro - Kies ...");
        setResizable(false);

        addButton.setText("<< Toevoegen");
        addButton.setToolTipText("Item toevoegen aan lijst");
        addButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addButtonActionPerformed(evt);
			}
		});
        
        deleteButton.setText("Verwijderen >>");
        deleteButton.setToolTipText("Item uit lijst verwijderen");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteButtonActionPerformed(evt);
			}
		});
        
        usedListScrollPane.setViewportView(usedList);

        unusedListScrollPane.setViewportView(unusedList);

        usedItemsLabel.setText("Items voor export: ");

        unusedItemsLabel.setText("Overige items: ");

        cancelButton.setText("Annuleren");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        okButton.setText("OK");
        okButton.setMaximumSize(new java.awt.Dimension(81, 23));
        okButton.setMinimumSize(new java.awt.Dimension(81, 23));
        okButton.setPreferredSize(new java.awt.Dimension(81, 23));
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(303, Short.MAX_VALUE)
                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cancelButton)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(usedListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(addButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(deleteButton, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addComponent(usedItemsLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(unusedItemsLabel)
                    .addComponent(unusedListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(usedItemsLabel)
                    .addComponent(unusedItemsLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(addButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteButton)
                        .addGap(125, 125, 125))
                    .addComponent(usedListScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(unusedListScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(okButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cancelButton, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed
    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	String s = (String) unusedList.getSelectedValue();
    	if (s != null) {
	    	ListModel lst = usedList.getModel();
	    	boolean add = true;
	    	for (int i = 0; i < lst.getSize(); i++) {
				if (s.equals(lst.getElementAt(i).toString())) {
					add = false;
				}
			}
	    	if (add) {
	    		DefaultListModel d = new DefaultListModel();
	        	int i =0;
	        	for (i =0; i < lst.getSize(); i++) {
	        		d.add(i, lst.getElementAt(i));
	        	}
	        	d.add(i,s);
	        	usedList.setModel(d);
	    	}
    	}
	}
    
    
    
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
		String s = (String) usedList.getSelectedValue();
		if (s != null) {
			ListModel lst = usedList.getModel();
			DefaultListModel d = new DefaultListModel();
	    	for (int i = 0; i < lst.getSize(); i++) {
	    		if (!s.equals(lst.getElementAt(i).toString())) {
	    			d.add(i, lst.getElementAt(i));
	    		}
	    	}
	    	
	    	usedList.setModel(d);
		}
	}

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                // TODO verwijderen
                new ExportChooser("Testen").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public Vector<Object> objectVector;
    public javax.swing.JButton addButton;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton deleteButton;
    public javax.swing.JButton okButton;
    private javax.swing.JLabel unusedItemsLabel;
    public javax.swing.JList unusedList;
    private javax.swing.JScrollPane unusedListScrollPane;
    private javax.swing.JLabel usedItemsLabel;
    public javax.swing.JList usedList;
    private javax.swing.JScrollPane usedListScrollPane;
    // End of variables declaration//GEN-END:variables

}
